package org.jeecg.modules.clues.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcoding.http.util.StringUtil;
import lombok.extern.slf4j.Slf4j;


import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.clues.entity.Clues;
import org.jeecg.modules.clues.service.ICluesService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 线索管理
 * @Author: jeecg-boot
 * @Date:   2020-05-04
 * @Version: V1.0
 */
@Slf4j
@Api(tags="线索管理")
@RestController
@RequestMapping("/clues")
public class CluesController extends JeecgController<Clues, ICluesService> {
	@Autowired
	private ICluesService cluesService;

	@Autowired
	private ISysDictService sysDictService;

	/**
	 * 分页列表查询
	 *
	 * @param clues
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "线索管理-分页列表查询")
	@ApiOperation(value="线索管理-分页列表查询", notes="线索管理-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(Clues clues,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<Clues> queryWrapper = new QueryWrapper<>();
		if (!StringUtil.isEmpty(clues.getKeyword())){
			queryWrapper.like("clues_title",clues.getKeyword());
		}
		if (null != clues.getCluesSource() ){
			queryWrapper.eq("clues_source",clues.getCluesSource());
		}

		if (null != clues.getCrawlerSource() ){
			queryWrapper.eq("crawler_source",clues.getCrawlerSource());
		}
		queryWrapper.orderByDesc("create_time");
		Page<Clues> page = new Page<Clues>(pageNo, pageSize);
		IPage<Clues> pageList = cluesService.selectCluesPage(page, queryWrapper);
		return Result.ok(pageList);
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "线索管理-通过id查询")
	@ApiOperation(value="线索管理-通过id查询", notes="线索管理-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		Clues clues = cluesService.getById(id);
		return Result.ok(clues);
	}


	 /**
	  * 获取线索关键词
	  *
	  * @return
	  */
	 @AutoLog(value = "线索管理-获取关键词")
	 @ApiOperation(value="线索管理-获取关键词", notes="线索管理-获取关键词")
	 @PostMapping(value = "/initKeywordList")
	 public Result<?> initKeywordList() {
		 List<Map<String,Object>> keywordList = cluesService.initKeywordList();
		 return Result.ok(keywordList);
	 }


}
